import { defineStore } from "pinia";
import { ref } from "vue";
import { getUploadBalance } from "@/server/api/itemInfo";

export const useUseStore = defineStore(
  "user",
  () => {
    let userId = ref(null); //id

    let countryCode = ref("PIFTWARE"); // 国家代码,默认PIFTWARE
    let regionId = ref("PIFTWARE"); // 地区Id，默认PIFTWARE 白云区 CN019001005
    let hoteCountryCode = ref("PIFTWARE"); //酒店国家代码
    let userInfo = ref({}); // 个人数据
    let activityInfo = ref(null); // 用户专区信息
    let levelRebate = ref(null); // 用户是否完成一级返佣
    let rebateQualification = ref(null); // 用户是否有一级团返佣资格

    const Upload = ref(0); //item次树
    const shopUpload = ref(0); //shop次数

    const itemId = ref(""); //品牌id
    const token = ref("");

    const ing = "https://sea.im/api";

    //提示是否开启？默认开启
    let showTip = ref(true);

    // 获取item次数
    const getUpload = async () => {
      const res = await getUploadBalance(itemId.value);
      // console.log("获取item次数", res.data.data);
      Upload.value = res.data.data;
    };

    return {
      itemId,
      userId,
      userInfo,

      ing,
      token,
      Upload,
      shopUpload,

      activityInfo,
      rebateQualification,
      levelRebate,

      getUpload,
      
      countryCode,
      hoteCountryCode,
      regionId,
      showTip,
    };
  },
  {
    persist: true,
  }
);
